package com.example.yunifang.adapter;

import java.util.ArrayList;

import com.example.yunifang.R;
import com.example.yunifang.adapter.FenleiFragmentAdapter.ViewHolder;
import com.example.yunifang.bean.FeiLeiBean.Data.GoodsBrief;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Fragment2GridViewAdapter extends BaseAdapter {

	ArrayList<GoodsBrief> data;
	Context context;

	public Fragment2GridViewAdapter(ArrayList<GoodsBrief> data, Context context) {
		super();
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if(convertView==null){
			convertView=View.inflate(context, R.layout.fragment2_grid_list_item, null);
			holder=new ViewHolder();
			holder.img=(ImageView) convertView.findViewById(R.id.fragment2_grid_item_img);
			holder.name=(TextView) convertView.findViewById(R.id.fragment2_grid_item_name);
			holder.price=(TextView) convertView.findViewById(R.id.fragment2_grid_item_price);
			holder.market_price=(TextView) convertView.findViewById(R.id.fragment2_grid_item_market);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		ImageLoader.getInstance().displayImage(data.get(position).goods_img, holder.img);
		holder.name.setText(data.get(position).goods_name);
		holder.price.setText(data.get(position).shop_price+"");
		holder.market_price.setText(data.get(position).market_price+"");
		holder.market_price.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG |Paint.ANTI_ALIAS_FLAG);
		return convertView;
	}
	public class ViewHolder{
		ImageView img;
		TextView name;
		TextView price;
		TextView market_price;
	}
}
